﻿using DynamicExpresso;
 
 

namespace com.iot.core.util
{
    public class CalcUtil
    {

        public static void TestCalc(string gs, decimal V)
        {
            gs = gs.ToUpper().Replace("V", V.ToString());
            Interpreter interpreter = new Interpreter() ;
            var d = interpreter.Eval<double>(gs,new Parameter[]
            {
                new Parameter(   "V", V)
            });
        
        }
        public static decimal Calc(string gs, decimal V)
        {
            try {
                if (string.IsNullOrEmpty(gs))
                {
                    return V;
                }
              //  gs = gs.ToUpper().Replace("V", V.ToString());
                Interpreter interpreter = new Interpreter();
                var d = interpreter.Eval<double>(gs, new Parameter[]
                {
                    new Parameter(   "V", V)
                }
                );

                return Convert.ToDecimal(d);
            }
            catch
            {
                return V;
            }
            
        }
       
    }
}
